package com.peng.test.arthas;

/**
 * DeadLock
 *
 * @author: lupeng6
 * @create: 2021/2/1 16:36
 */
public class DeadLock {

    public static void main(String[] args) {
        Object obj1 = new Object();
        Object obj2 = new Object();

        new Thread(() -> {
            synchronized (obj1) {
                System.out.println("synchronized obj1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (obj2) {
                    System.out.println(1);
                }
            }
        }).start();

        new Thread(() -> {
            synchronized (obj2) {
                System.out.println("synchronized obj2");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (obj1) {
                    System.out.println(1);
                }
            }
        }).start();
    }

}
